package org.contacts.action.servlet;


import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.contacts.dao.Contact;
import org.contacts.dao.impl.ContactModel;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

public class ListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        ContactModel contactModel = new ContactModel();
        ArrayList<Contact> contactList = contactModel.getAllContacts();

        request.setAttribute("contacts", contactList);
        RequestDispatcher dispatcher = request.getRequestDispatcher("list.jsp");
        dispatcher.forward(request, response);
    }
}
